<template>
  <div class="prompt-generator">
    <h2>提示词生成</h2>

    <el-form :model="form" label-position="top">
      <el-form-item label="视频主题">
        <el-input 
          v-model="form.topic" 
          placeholder="请输入视频主题，例如：人工智能发展历史"
          size="large"
        />
      </el-form-item>

      <el-form-item label="视频时长(分钟)">
        <el-input-number 
          v-model="form.duration" 
          :min="1" 
          :max="60" 
          :step="1"
          size="large"
          style="width: 180px"
        />
      </el-form-item>

      <el-form-item label="目标受众">
        <el-select 
          v-model="form.audience" 
          placeholder="请选择目标受众"
          size="large"
          style="width: 100%"
        >
          <el-option label="初学者" value="beginner" />
          <el-option label="中级用户" value="intermediate" />
          <el-option label="专业人士" value="expert" />
        </el-select>
      </el-form-item>

      <el-form-item label="风格偏好">
        <el-select 
          v-model="form.style" 
          placeholder="请选择视频风格"
          size="large"
          style="width: 100%"
        >
          <el-option label="严谨专业" value="professional" />
          <el-option label="轻松活泼" value="casual" />
          <el-option label="深入浅出" value="educational" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button 
          type="primary" 
          @click="generatePrompt" 
          :loading="loading"
          size="large"
          style="width: 100%"
        >
          生成提示词
        </el-button>
      </el-form-item>
    </el-form>

    <div v-if="generatedPrompt" class="generated-prompt">
      <h3>生成的提示词：</h3>
      <div class="prompt-box">
        <p>{{ generatedPrompt }}</p>
        <el-button 
          type="primary"
          @click="copyPrompt"
          size="large"
        >
          复制提示词
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'
import { deepseekApi } from '@/api/deepseek'

interface PromptForm {
  topic: string
  duration: number
  audience: string
  style: string
}

const form = ref<PromptForm>({
  topic: '',
  duration: 5,
  audience: 'beginner',
  style: 'educational'
})

const loading = ref(false)
const generatedPrompt = ref('')

const generatePrompt = async () => {
  if (!form.value.topic) {
    ElMessage.warning('请输入视频主题')
    return
  }

  try {
    loading.value = true

    const response = await deepseekApi.generatePrompt({
      topic: form.value.topic,
      duration: form.value.duration,
      audience: form.value.audience,
      style: form.value.style
    })

    if (response && response.data) {
      generatedPrompt.value = response.data
    } else {
      throw new Error('生成提示词失败')
    }
  } catch (error) {
    ElMessage.error('生成提示词失败，请重试')
    console.error('生成提示词失败:', error)
  } finally {
    loading.value = false
  }
}

const copyPrompt = async () => {
  try {
    await navigator.clipboard.writeText(generatedPrompt.value)
    ElMessage.success('提示词已复制到剪贴板')
  } catch (error) {
    ElMessage.error('复制失败，请手动复制')
    console.error('复制失败:', error)
  }
}
</script>

<style scoped>
.prompt-generator {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
}

h2 {
  text-align: center;
  margin-bottom: 30px;
  font-size: 24px;
}

.el-form-item {
  margin-bottom: 20px;
}

.generated-prompt {
  margin-top: 30px;
}

h3 {
  margin-bottom: 15px;
  font-size: 18px;
}

.prompt-box {
  background: #f5f7fa;
  padding: 20px;
  border-radius: 4px;
  margin-bottom: 20px;
}

.prompt-box p {
  white-space: pre-wrap;
  line-height: 1.6;
  margin-bottom: 15px;
}

@media (max-width: 600px) {
  .prompt-generator {
    padding: 15px;
  }
  
  h2 {
    font-size: 20px;
    margin-bottom: 20px;
  }
}
</style>